<!--培训计划-->
<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item class="form-button-right">
				<el-button v-auth="'module:train:save'" type="primary" @click="addOrUpdateHandle()">新增培训计划</el-button>
			</el-form-item>

			<el-form-item label="培训状态">
				<el-select v-model="state.queryForm.state" placeholder="请选择"></el-select>
			</el-form-item>
			<el-form-item label="分类">
				<el-select v-model="state.queryForm.typeId" placeholder="请选择"></el-select>
			</el-form-item>
			<el-form-item label="">
				<KeyQuery v-model="state.queryForm.keyword" @getDataList="getDataList()"/>
			</el-form-item>
		</el-form>

		<div class="card" :key="index" v-for="(item, index) of state.dataList">
			<el-card>
				<el-row>
					<el-col :span="7" class="left-and-centre">
						<h1>{{ item.name }}</h1>
						<div>分类：{{ item.typeId }}</div>
						<div>培训计划时间：{{ item.startDate + '—' + item.endDate }}</div>
					</el-col>
					<el-col :span="1">
						<el-divider direction="vertical" style="height: 100%"></el-divider>
					</el-col>
					<el-col :span="8" class="left-and-centre">
						<h1 v-if="item.stateId === '0'" class="start-0">{{ item.stateId }}1</h1>
						<h1 v-if="item.stateId === '1'" class="start-1">{{ item.stateId }}2</h1>
						<h1 v-if="item.stateId === '2'" class="start-2">{{ item.stateId }}3</h1>
						<div>
							培训总人数 <span>{{ item.population }}</span
							>课程<span>{{ item.isAll }}</span>
						</div>
					</el-col>
					<el-col :span="8" class="right">
						<el-button v-auth="'module:assetStorage:update'" type="primary" link @click="openTag(item.id)">查看详情</el-button>
						<el-button v-auth="'module:assetStorage:update'" type="primary" link @click="addOrUpdateHandle(item.id)">调整计划时间</el-button>
						<el-button v-auth="'module:assetStorage:delete'" type="primary" link @click="deleteBatchHandle(item.id)">完成培训</el-button>
					</el-col>
				</el-row>
			</el-card>
		</div>

		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList"></add-or-update>
		<!-- <info ref="infoRef" @refreshDataList="getDataList" width="72%"></info> -->
	</el-card>
</template>
<style>
.card {
	margin: 0 0 20px 0;
}
.card:hover {
	box-shadow: 0.3em 0.3em 1em rgba(0, 0, 0, 0.3);
}

.start-0 {
	color: #717070;
}

.start-1 {
	color: #098e50;
}

.start-2 {
	color: #9c4d4d;
}

.left-and-centre > * {
	margin: 10px 0;
	> span {
		background-color: #ddd;
		padding: 5px 10px;
		border-radius: 15px;
		margin: 0 10px;
	}
}

.left-and-centre > div {
	color: #71707094;
}
.right {
	align-self: center;
	text-align: right;
}
</style>

<script setup lang="ts" name="ModuleTrainIndex">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import AddOrUpdate from './plane/plan-a-u.vue'
import Info from './plane/plan-info.vue'
import { findListByDictId } from '@/api/nb/business/dictionaries_subset'
import { useRoute, useRouter } from 'vue-router'

const state: IHooksOptions = reactive({
	dataListUrl: '/nb/train/page',
	deleteUrl: '/nb/train/delete',
	queryForm: {}
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.dataPList = dbList.value
	addOrUpdateRef.value.init(id)
}

const infoRef = ref()
const infoHandle = (id?: number) => {
	infoRef.value.dataPList = dbList.value
	infoRef.value.init(id)
}

//培训类型 下拉
const dbList = ref([])
const getDbList = () => {
	return findListByDictId({
		params: {
			code: 'PeiXunJiHua'
		}
	}).then(res => {
		dbList.value = res.data
	})
}
getDbList()
const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)

const router = useRouter()
const openTag = (id: string) => {
	router.push({ name: '组件查询', query: { id: id } })
}
</script>
